import { homePageTotal } from "@/api/homePage";

const state = {
  returnTaskNumber: 0, //退回待处理任务数
  taskNumber: 0, //待处理任务数
  businessCollaborationNum: 0, //当前业务协同数
  finishTask:0,//已处理任务数
  doneCollaborationNum:0,
};
const mutations = {
  SET_RETURNTASK: (state, returnTaskNumber) => {
    state.returnTaskNumber = returnTaskNumber;
  },
  SET_TASK: (state, taskNumber) => {
    state.taskNumber = taskNumber;
  },
  SET_FINISHTASK: (state, finishTask) => {
    state.finishTask = finishTask;
  },
  SET_COLLABORATION: (state, businessCollaborationNum) => {
    state.businessCollaborationNum = businessCollaborationNum;
  },
  SET_DONECOLLABORATION: (state, doneCollaborationNum) => {
    state.doneCollaborationNum = doneCollaborationNum;
  },
};

const actions = {
  getTotal({ commit, rootState }) {
    let params = {
      oucode: rootState.user.oucode,
      deptId: rootState.user.dept.deptId,
      userId: rootState.user.userId,
    };
    return new Promise((resolve, reject) => {
      homePageTotal(params)
        .then((res) => {
          let data = res.data;
          console.log(data);
          commit("SET_TASK", data.taskNumber);
          commit("SET_RETURNTASK", data.returnTaskNumber);
          commit("SET_FINISHTASK", data.finishTask);
          commit("SET_COLLABORATION", data.businessCollaborationNum);
          commit("SET_DONECOLLABORATION", data.doneCollaborationNum);
          resolve();
        })
        .catch((error) => {
          reject(error);
        });
    });
  },
};

export default {
  state,
  mutations,
  actions,
};
